from selenium import webdriver
import  time

# 浏览器基础操作
# browser = webdriver.Chrome()
# browser.get("https://www.taobao.com")
# browser.maximize_window()
# print(browser.title)
# print(browser.current_url)
# print(browser.page_source)
# time.sleep(5)
# browser.get("https://huodong.taobao.com/wow/a/act/tao/dailygroup/23509/24308/wupr?spm=a21bo.jianhua/a.banner.d1.5af92a89a7608r&wh_pid=daily-557212&disableNav=YES&status_bar_transparent=true&custom_content_source=a2113w.29944537")
# time.sleep(5)
# browser.back()
# time.sleep(5)
# browser.forward()
# browser.refresh()
# time.sleep(5)
# browser.quit()

# 精确定位 与 模糊定位
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from time import sleep
#
# driver = webdriver.Chrome()
# driver.maximize_window()
# driver.get("https://www.hao123.com/")
#
# # r = driver.find_element(By.PARTIAL_LINK_TEXT,"哔哩")
# # r = driver.find_element(By.LINK_TEXT,"12306")
# r = driver.find_element(By.CLASS_NAME,"input-hook")
# r.send_keys("回家过年")
# sleep(3)
# g = driver.find_element(By.CLASS_NAME,"g-cp")
# g.click()
# sleep(3)
#
# driver.quit()


# 利用ID定位
# from selenium import webdriver
# from time import sleep
# from selenium.webdriver.common.by import By
# from selenium.webdriver.common.action_chains import ActionChains
#
#
# browser = webdriver.Chrome()
# browser.maximize_window()
# browser.get("https://www.taobao.com")
# browser.find_element(By.ID,"q").send_keys("衣服")
# search = browser.find_element(By.CLASS_NAME,"btn-search")
# search.click()
# # browser.get("https://s.taobao.com/search?q=%E7%94%B5%E8%84%91&spm=a21bo.jianhua%2Fa.201867-main.d2_first.33e82a89XmUipN")
# # input_ = browser.find_element(By.ID,"fm-login-id")
# # input_.send_keys("15715660837")
# # browser.back()
# # browser.find_element(By.NAME,"commend").send_keys("")
# # father.find_element(By.ID,"search").click()
# sleep(10)
# browser.quit()

#利用name定位
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from time import sleep
#
# driver = webdriver.Chrome()
# driver.get("https://www.hao123.com/")
# driver.maximize_window()
# r = driver.find_element(By.NAME,"word")
# r.send_keys("天龙八部")
# g = driver.find_element(By.CLASS_NAME,"s_btn")
#
# g.click()
# sleep(3)
# driver.quit()


# 利用tag_name
#
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from time import sleep
#
# driver = webdriver.Chrome()
# driver.get("https://www.hao123.com/")
# driver.maximize_window()
#
# r = driver.find_element(By.TAG_NAME,"input")
# r.send_keys("宇智波鼬")
# sleep(3)
# # print(r)
#
# driver.quit()


# 利用Css_selector定位
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from time import sleep
#
# driver = webdriver.Chrome()
# driver.get("https://www.baidu.com/")
# driver.maximize_window()
#
# r = driver.find_element(By.CSS_SELECTOR,"a[href='http://news.baidu.com']")
# r.click()
# sleep(5)
#
# driver.quit()

# 利用XPATH定位
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
driver.maximize_window()

r = driver.find_element(By.XPATH,"//input[@id='kw']")
r.send_keys("天龙八部")
sleep(5)
driver.quit()
